from django.db import models
from Goods.models import GoodsBase
class User_Account(models.Model):
    ROLE = (
        (u'admin', u'admin'),
        (u'super_admin', u'super_admin'),
        (u'user', u'user'),
    )
    username = models.CharField(max_length=128, unique=True)  # 账号
    password = models.CharField(max_length=256)  # 密码

    UserID = models.OneToOneField(
        'User_Information', null=True, blank=True, on_delete=models.CASCADE, verbose_name=u'姓名')
    
    role = models.CharField(
        max_length=30,null=True,blank=True, verbose_name=u'权限', choices=ROLE)
    
    def __str__(self):
        return self.username

    class Meta:
        verbose_name_plural = "用户密码"

class User_Token(models.Model):
    user = models.OneToOneField('User_Account',on_delete=models.CASCADE)
    token = models.CharField(max_length=64)

class User_Information(models.Model):
    GENDER_CHOICES = (
        (u'男', u'男'),
        (u'女', u'女'),
    )

    name = models.CharField(max_length=30, verbose_name=u'姓名')
    porteait = models.ImageField(
        upload_to='static/images/UserPorteait',null=True, blank=True, verbose_name=u'用户头像')

    gender = models.CharField(
        max_length=30, verbose_name=u'性别', choices=GENDER_CHOICES)

    email = models.EmailField()

    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = "用户主体信息"


class User_Address(models.Model):
    UserID = models.OneToOneField(
        'User_Information', null=True, blank=True, on_delete=models.CASCADE, verbose_name=u'姓名')
    name = models.CharField(max_length=30, verbose_name=u'收件人姓名')
    phone = models.IntegerField(null=True, blank=True, verbose_name=u'收件人手机')
    default = models.BooleanField(default=False, verbose_name=u'是否默认')
    province = models.CharField(max_length=30, verbose_name=u'省')
    city = models.CharField(max_length=30, verbose_name=u'市')
    area = models.CharField(max_length=30, verbose_name=u'区')
    street = models.CharField(max_length=30, verbose_name=u'街道')

    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = "用户地址"

class User_Collection(models.Model):
    user = models.ForeignKey('User_Account',on_delete=models.CASCADE,verbose_name=u'用户')
    goodesID = models.CharField(max_length=230, verbose_name=u'商品ID')
    title = models.CharField(max_length=300, verbose_name=u'标题')
    img = models.TextField(verbose_name=u'主图地址')
    price = models.FloatField(null=True, blank=True, verbose_name=u'价格')

class Account_validation(models.Model):
    token = models.ForeignKey('User_Token',on_delete=models.CASCADE,verbose_name=u'用户')
    key = models.CharField(max_length=230, verbose_name=u'键')
    value = models.CharField(max_length=230, verbose_name=u'值')
    
class VfCode(models.Model):
    # 图像验证 邮箱验证
    key = models.CharField(max_length=230, verbose_name=u'键')
    value = models.CharField(max_length=230, verbose_name=u'值')
    star_time = models.DateTimeField(auto_now_add=True,verbose_name=u'创建日期')   
    last_time = models.DateTimeField(auto_now=True,verbose_name=u'最后一次修改日期')  

class ShoppingCart(models.Model):
    user = models.ForeignKey('User_Account',on_delete=models.CASCADE)
    Goods = models.ForeignKey(to='Goods.GoodsBase',null=True, blank=True,on_delete=models.CASCADE)
    Goodspackage = models.ForeignKey(to='Goods.Goodspackage',null=True, blank=True,on_delete=models.CASCADE,verbose_name=u'套餐')
    number = models.IntegerField(null=True, blank=True, verbose_name=u'数量')

    def __str__(self):
        return self.user

    class Meta:
        verbose_name_plural = "用户购物车"